package com.study.zzedu.ui.graduateservice;


import android.content.Context;
import android.text.TextUtils;

import com.study.zzedu.base.BaseModel;
import com.study.zzedu.http.OnResultListener;
import com.study.zzedu.utils.AppConstant;
import com.study.zzedu.utils.LogUtil;
import com.study.zzedu.utils.OkHttpUtils;

import org.json.JSONArray;
import org.json.JSONObject;

public class GraduateServiceModel extends BaseModel {
    /*
    学生查询申请学位条件
    */
    public void queryApplyConditions(Context context, final OnResultListener resultListener) {
        OkHttpUtils.getInstance(context).postJson(OkHttpUtils.BASE_URL + "/degreeManager/queryApplyConditions",  "{}", new OkHttpUtils.HttpCallBack() {

            @Override
            public void onSuccess(String obj) {
                try {
                    JSONObject jObject = new JSONObject(obj);
                    if (0 == jObject.getInt("code")) {
                        JSONArray jsonArray = jObject.getJSONArray("data");
                        LogUtil.e("Forget", "学生查询申请学位条件成功");
                        if (jsonArray.length() > 0) {
                        }
                        resultListener.onSuccess(obj);
                    } else {
                        LogUtil.e("Forget", "学生查询申请学位条件失败");
                        resultListener.onError(jObject.get("message").toString());
                    }
                } catch (Exception e) {
                    e.toString();
                }
            }

            @Override
            public void onSuccess(JSONObject obj) {
                resultListener.onSuccess(obj.toString());
            }

            @Override
            public void onError(String msg) {
                LogUtil.e("Forget", "学生查询申请学位条件失败");
                resultListener.onError(msg);
            }
        });
    }

    /*
    学生申请学位
    */
    public void applyXueWei(Context context, final OnResultListener resultListener) {
        OkHttpUtils.getInstance(context).postJson(OkHttpUtils.BASE_URL + "/degreeManager/applyXueWei",null,new OkHttpUtils.HttpCallBack(){

            @Override
            public void onSuccess(JSONObject obj) {
                try {
                    if (0 == obj.getInt("code")) {
                        LogUtil.e("Forget", "学生申请学位成功");
                        //JSONArray jsonArray = obj.getJSONArray("data");
                        resultListener.onSuccess(obj.toString());
                    } else {
                        LogUtil.e("Forget", "学生申请学位失败");
                        resultListener.onError(obj.get("message").toString());
                    }
                } catch (Exception e) {
                    e.toString();
                }
            }

            @Override
            public void onError(String msg) {
                resultListener.onError(msg);
            }
        });

    }

}
